//
//  ZLButton.m
//  ZLCustomViews
//
//  Created by 赵振磊 on 2024/1/27.
//

#import "ZLButton.h"

@implementation ZLButton

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat imageWidth = self.imageView.frame.size.width;
    CGFloat imageHeight = self.imageView.frame.size.height;
    CGFloat titleWidth = self.titleLabel.frame.size.width;
    CGFloat titleHeight = self.titleLabel.frame.size.height;
    if (imageWidth == 0 || imageHeight == 0 || titleWidth == 0 || titleHeight == 0) {
        return;
    }
    switch (self.zlImagePositon) {
        case ZLImagePositonRight:
            self.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth + self.zlSpacing, 0, -titleWidth);
            self.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageHeight + self.zlSpacing);
            break;
        case ZLImagePositonTop:
            self.imageEdgeInsets = UIEdgeInsetsMake(-titleHeight - self.zlSpacing, 0, 0, -titleWidth);
            self.titleEdgeInsets = UIEdgeInsetsMake(imageHeight + self.zlSpacing, -imageWidth, 0, 0);
            break;
        case ZLImagePositonBottom:
            self.imageEdgeInsets = UIEdgeInsetsMake(titleHeight + self.zlSpacing, 0, 0, -titleWidth);
            self.titleEdgeInsets = UIEdgeInsetsMake(-titleHeight - self.zlSpacing, -imageWidth, 0, 0);
            break;
        default:
            self.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, self.zlSpacing);
            self.titleEdgeInsets = UIEdgeInsetsMake(0, self.zlSpacing, 0, 0);
            break;
    }
}

@end
